//
//  UIScrollView+JMRefresh.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2019/8/7.
//  Copyright © 2019年 Lssyyy. All rights reserved.
//

#import "UIScrollView+JMRefresh.h"
#import "JMRefreshHeader.h"
#import "JMRefreshFooter.h"
@implementation UIScrollView (JMRefresh)
/// 添加下拉刷新控件
- (MJRefreshHeader *)jm_addHeaderRefresh:(void(^)(MJRefreshHeader *header))refreshingBlock {
    
    __weak typeof(&*self) weakSelf = self;
//    JMRefreshHeader *mj_header = [JMRefreshHeader headerWithRefreshingBlock:^{
//        __strong typeof(&*weakSelf) strongSelf = weakSelf;
//        !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
//    }];
    MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        __strong typeof(&*weakSelf) strongSelf = weakSelf;
        !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
    }];
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    mj_header.automaticallyChangeAlpha = YES;
    // Configure normal mj_header
    self.mj_header = mj_header;
    return mj_header;
}

/// 添加上拉加载控件
- (MJRefreshFooter *)jm_addFooterRefresh:(void(^)(MJRefreshFooter *footer))refreshingBlock {
    __weak typeof(&*self) weakSelf = self;
//    JMRefreshFooter *mj_footer = [JMRefreshFooter footerWithRefreshingBlock:^{
//        __strong typeof(&*weakSelf) strongSelf = weakSelf;
//        !refreshingBlock?:refreshingBlock((MJRefreshAutoNormalFooter *)strongSelf.mj_footer);
//    }];
    MJRefreshAutoNormalFooter *mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        __strong typeof(&*weakSelf) strongSelf = weakSelf;
        !refreshingBlock?:refreshingBlock((MJRefreshAutoNormalFooter *)strongSelf.mj_footer);
    }];
    self.mj_footer = mj_footer;
    return mj_footer;
}
@end
